package com.yunfeisoft.business.dao.impl;

import com.yunfeisoft.base.model.User;
import com.yunfeisoft.business.dao.inter.NurseScheduleDao;
import com.yunfeisoft.business.model.NurseSchedule;
import com.yunfeisoft.common.base.BaseDaoImpl;
import com.yunfeisoft.common.sql.builder.SelectBuilder;
import com.yunfeisoft.common.sql.builder.WhereBuilder;
import com.yunfeisoft.common.utils.Page;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * ClassName: NurseScheduleDaoImpl
 * Description: 护士排班表Dao实现
 * Author: Jackie liu
 * Date: 2020-05-22
 */
@Repository
public class NurseScheduleDaoImpl extends BaseDaoImpl<NurseSchedule, String> implements NurseScheduleDao {

    @Override
    public Page<NurseSchedule> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        if (params != null) {
            initPageParam(wb, params);
        }
        return queryPage(wb);
    }

    @Override
    public List<NurseSchedule> listByTime(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        if (params != null) {
            wb.andLessEquals("scheduleDate", params.get("end"));
            wb.andGreaterEquals("scheduleDate", params.get("start"));
        }
        SelectBuilder builder = getSelectBuilder("n");
        builder.column("u.name as username")
                .join(User.class).alias("u")
                .on("u.id = n.userId").build();
        return query(builder.getSql(), wb);
    }
}